package com.sunnada.edu.system.pub.common;

import java.util.Random;

/**
 * 0-9随机数生成器
 * 
 * @author zjc 2015-07-28
 * 
 */
public class RandomTool {  
	static Random r=new Random();
	static String ssource="0123456789";
	static String num="23456789";
	static String letter="ABCDEFGHJKMNPQRSTVUWXYZ";
	static char[]src=ssource.toCharArray();
	static char[]numchar=num.toCharArray();
	static char[]letterchar=letter.toCharArray();
	//产生随机数字符串
	public static String randString( int length){
		char []buf =new char[length];
		int rnd;
		for(int i=0;i<length;i++){
			rnd=Math.abs(r.nextInt())%src.length;
			buf[i]=src[rnd];
		}
		return new String(buf);
	}
	//产生随机数字
	public static String randNum( int length){
		char []buf =new char[length];
		int rnd;
		for(int i=0;i<length;i++){
			rnd=Math.abs(r.nextInt())%numchar.length;
			buf[i]=numchar[rnd];
		}
		return new String(buf);
	}
	//产生随机大写字母
	public static String randLetter( int length){
		char []buf =new char[length];
		int rnd;
		for(int i=0;i<length;i++){
			rnd=Math.abs(r.nextInt())%letterchar.length;
			buf[i]=letterchar[rnd];
		}
		return new String(buf);
	}
	//生成密钥
	public static String productKey(String source ,int length){
		char []buf =new char[length];
	    char [] src=source.toCharArray();
		int rnd;
		for(int i=0;i<length;i++){
			rnd=Math.abs(r.nextInt())%src.length;
			buf[i]=src[rnd];
		}
		return new String(buf);
	}
	
    public static void main(String[] args) { 
        String s =RandomTool.randNum(3)+"@"+RandomTool.randLetter(4);
        System.out.println(s);
    }
	
	
}
